package com.huilian.tool.weixin.controller;

import com.huilian.tool.weixin.service.WeixinOpenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 谢洛涛
 * @date 2023/3/29 11:07
 */
@Slf4j
@RequestMapping("/api/weixinOpen")
@Controller
public class WeixinOpenController {
    @Autowired
    private WeixinOpenService weixinOpenService;

    /**
     * 微信官方每十分钟会回调一次 更新一次
     */
    @PostMapping("/getticket")
    @ResponseBody
    public void getTicket(HttpServletRequest request) throws Exception {
        weixinOpenService.getWxOpenTicket(request);
    }



    /**
     * 微信开放平台微信消息处理
     *
     * @param
     * @return
     */
    @PostMapping("/callback/{appId}")
    @ResponseBody
    public String wxOpenMessageManage(HttpServletRequest request, @PathVariable String appId) {
        try {
            return weixinOpenService.messageManage(request, appId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
